package com.wicket.okrframework.web.contorller;

import com.github.pagehelper.Page;
import com.wicket.okrframework.biz.service.FunctionalGoalService;
import com.wicket.okrframework.biz.service.dto.req.AddTargetDetailsReqDto;
import com.wicket.okrframework.biz.service.dto.req.QueryTargetDetailsListReqDto;
import com.wicket.okrframework.biz.service.dto.req.UpdateTargetDetailReqDto;
import com.wicket.okrframework.biz.service.dto.res.AddTargetDetailsRespDto;
import com.wicket.okrframework.biz.service.dto.res.QueryTargetDetailsListRespDto;
import com.wicket.okrframework.biz.service.dto.res.UpdateTargetDetailRespDto;
import com.wicket.okrframework.common.ro.OkrResult;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@RestController
@RequestMapping("/base/functionalGoal/")
public class FunctionalGoalController {

    @Autowired
    FunctionalGoalService functionalGoalService;

    /**
   * D1-3新增目标职责明细
   */
    @PostMapping("addTargetDetails")
    public OkrResult<AddTargetDetailsRespDto> addTargetDetails(@RequestBody @Validated AddTargetDetailsReqDto reqDTO){
    return OkrResult.success(functionalGoalService.addTargetDetails(reqDTO));
    }

    /**
   * D1-3 查询目标职责明细列表
   */
    @PostMapping("queryTargetDetailsList")
    public OkrResult<QueryTargetDetailsListRespDto> queryTargetDetailsList(@RequestBody @Validated QueryTargetDetailsListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryTargetDetailsListRespDto retData = functionalGoalService.queryTargetDetailsList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-3修改目标职责明细
   */
    @PostMapping("updateTargetDetail")
    public OkrResult<UpdateTargetDetailRespDto> updateTargetDetail(@RequestBody @Validated UpdateTargetDetailReqDto reqDTO){
    return OkrResult.success(functionalGoalService.updateTargetDetail(reqDTO));
    }
}
